// ---------------------------------------------------------------------------------------------------------------------
//   Copyright (c) SRT Solutions 2009. All rights reserved.
// ---------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

using SRTSolutions.Elevate;

namespace SRTSolutions.Elevate.Guide._001_Sequences._001_CreatingSequences
{
    public class _002_NumericalSequencesWithThrough
    {
        [Test]
        public void Through()
        {
            //if we want to easily generate a sequence of incrementing numbers,
            //we can do it like this
            IEnumerable<int> numbers = 1.Through(15);

            var expected = Seq.Build(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
            Assert.AreEqual(expected, numbers);
        }

        [Test]
        public void ThroughBackwards()
        {
            //we can also start at a bigger number and generate numbers in reverse
            var numbers = 20.Through(10);

            var expected = Seq.Build(20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10);
            Assert.AreEqual(expected, numbers);
        }

        [Test]
        public void ThroughWithAStep()
        {
            //we can specify the step to use when using Through like this
            var numbers = 5.Through(30, 5);

            var expected = Seq.Build(5, 10, 15, 20, 25, 30);
            Assert.AreEqual(expected, numbers);
        }

        #region Unit Tests

        [Test]
        public void ThroughEqual()
        {
            Assert.AreEqual(Seq.Build<int>(10), 10.Through(10));
        }

        [Test]
        public void ThroughWithStepArgumentExceptionForwards()
        {
            Assert.Throws<ArgumentException>(() => 10.Through(20, -1));
        }

        [Test]
        public void ThroughWithStepArgumentExceptionBackwards()
        {
            Assert.Throws<ArgumentException>(() => 50.Through(10, 1));
        }

        [Test]
        public void ThroughWithStepZeroStep()
        {
            Assert.Throws<ArgumentException>(() => 50.Through(10, 0));
        }

        [Test]
        public void ThroughEndAtDifferentNumber()
        {
            var results = 0.Through(11, 2);
            var expected = Seq.Build(0, 2, 4, 6, 8, 10);
            Assert.AreEqual(expected, results);
        }

        #endregion
    }
}
